A BGP router determines the best path to a destination network. This path is then eligible for use in the IP forwarding table and the router also advertises the path to its eBGP peers. To choose the best of multiple BGP routes to a destination, the router executes a best path algorithm.
The algorithm chooses a route in the following order:
highest weight
Weight is a locally significant parameter associated with each BGP peer. You can use the weight to influence which peer paths the router uses.
highest local preference
The local preference has global significance within an AS. You can manipulate the preference using route policies to influence path selection.
prefer locally originated paths
The router prefers a path locally originated using the network, redistribution, or aggregate command over a path learned through a BGP update. The router prefers local paths sourced by network or redistribute commands over local aggregates sourced by the aggregate address command.
shortest AS path
The AS path parameter specifies the autonomous systems that the network prefix traversed. The AS path commonly determines the best path. For example, a router can choose a path based on whether the network passed through a specific AS. You can configure a route policy to match the AS, and then modify the local preference. Also, you can pad the AS path before the AS advertises it to a peer AS, so that downstream routers are less likely to prefer the advertised network path.
The AS_CONFED_SEQUENCE length will also be considered while picking the best path inside the confederation.
lowest origin type
The order of preference is IGP, EGP, INC (incomplete).
lowest MED
The MED parameter influences the preferred path from a remote AS to the advertising AS. This parameter applies when there are multiple exit points from the remote AS to the advertising AS. A lower MED value indicates a stronger path preference than a higher MED value. By default, the MED attribute is ignored as specified by the BGP global parameter Always Compare MED except when the routes come from the same AS. This parameter must be enabled for MEDs to be compared (and for this step of the best path algorithm to execute).
The router compares MEDs regardless of what the first (neighboring) AS specified in the AS_PATH. Deterministic MED, when enabled, means that the first AS of the multiple paths must be the same. Paths received with no MED are assigned a MED of 0, unless the global BGP parameter Missing Is Worst is enabled. If so, received paths are assigned a MED of 4 294 967 294. Missing is Worst is enabled by default. The "no-med-path-is-worst" flag has an impact only when the “First AS” or the "Most Left AS" is the same for multiple routes received. The router changes paths received with a MED of 4 294 967 295 to 4 294 967 294 before insertion into the BGP table.
Note
You cannot enable or disable the MED selection process. BGP aggregation does not occur when routes have different MEDs or next hops.
When MED value is set in route-map configuration, the configured MED value is not applicable if it is already set in the associated Path Attribute.
When router A sets MED value of 100 by route-map, it will send Path Attribute with MED=100 to EBGP peer B.
Router B sends Path Attribute with MED=100 to IBGP peer C.
If the route-map is configured with "set MED 200", then router C does not apply MED=200 to the Path Attribute as it is already set to 100 when it is received from router B.
Router D will get Path Attribute with MED=100 so that router C does not influence router D when it selects the best route.
Set: Set: MED100 MED100 MED:100 MED200 MED:100 A------------------B-------------------------C-----------------------------D EBGP IBGP EBGPExample: If Prefix: X is set as MED=100 from router A, it will be received at B with MED=100, and will carry same MED=100 value to router C, as it is an IBGP peer. Router C will not propagate MED=100 value to D as MED is a non-transitive attribute, so MED can travel maximum of 1 AS.
lowest IGP metric to the BGP next-hop
If multiple paths exist whose BGP next-hop is reachable through an IGP, the path with the lowest IGP metric to the BGP next-hop is chosen.
prefer external paths (learned by eBGP) over internal paths (iBGP)
The system prefers external paths over internal paths.
if Equal Cost Multipath (ECMP) is enabled, insert up to four paths in the routing table
If you enable ECMP, multiple BGP learned routes that use the same metric to different IP next-hops are installed in the IP forwarding table for traffic load-balancing purposes.
lowest router ID
The lowest router ID, or Circuitless IP (CLIP) address, is preferred.